package com.ruoyi.web.controller.statistics;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.statistics.domain.SysFriendShip;
import com.ruoyi.statistics.service.ISysFriendShipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 好友联系Controller
 * 
 * @author ruoyi
 * @date 2022-01-16
 */
@RestController
@RequestMapping("/statistics/ship")
public class SysFriendShipController extends BaseController
{
    @Autowired
    private ISysFriendShipService sysFriendShipService;

    /**
     * 查询好友联系列表
     */
    @PreAuthorize("@ss.hasPermi('statistics:ship:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFriendShip sysFriendShip)
    {
        startPage();
        List<SysFriendShip> list = sysFriendShipService.selectSysFriendShipList(sysFriendShip);
        return getDataTable(list);
    }

    /**
     * 查询好友联系列表
     */
    @GetMapping("/viewList")
    public TableDataInfo viewList(SysFriendShip sysFriendShip)
    {
        startPage();
        sysFriendShip.setUserId(getUserId());
        List<SysFriendShip> list = sysFriendShipService.selectSysFriendShipViewList(sysFriendShip);
        return getDataTable(list);
    }

    /**
     * 导出好友联系列表
     */
    @PreAuthorize("@ss.hasPermi('statistics:ship:export')")
    @Log(title = "好友联系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFriendShip sysFriendShip)
    {
        List<SysFriendShip> list = sysFriendShipService.selectSysFriendShipList(sysFriendShip);
        ExcelUtil<SysFriendShip> util = new ExcelUtil<SysFriendShip>(SysFriendShip.class);
        util.exportExcel(response, list, "好友联系数据");
    }

    /**
     * 获取好友联系详细信息
     */
    @PreAuthorize("@ss.hasPermi('statistics:ship:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysFriendShipService.selectSysFriendShipById(id));
    }

    /**
     * 新增好友联系
     */
    @Log(title = "好友联系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFriendShip sysFriendShip)
    {
        sysFriendShip.setUserId(getUserId());
        return toAjax(sysFriendShipService.insertSysFriendShip(sysFriendShip));
    }

    /**
     * 修改好友联系
     */
    @PreAuthorize("@ss.hasPermi('statistics:ship:edit')")
    @Log(title = "好友联系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFriendShip sysFriendShip)
    {
        return toAjax(sysFriendShipService.updateSysFriendShip(sysFriendShip));
    }

    /**
     * 修改好友联系
     */
    @PreAuthorize("@ss.hasPermi('statistics:ship:edit')")
    @Log(title = "好友联系", businessType = BusinessType.UPDATE)
    @PutMapping("/modifyState/{ids}")
    public AjaxResult editState(@PathVariable Long[] ids)
    {
        return toAjax(sysFriendShipService.updateSysFriendStatusShip(ids));
    }

    /**
     * 删除好友联系
     */
    @Log(title = "好友联系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysFriendShipService.deleteSysFriendShipByIds(ids));
    }
}
